
function getSelect(value,obj){
       var id = value;
           $.ajax({
        url: $.getEnvUrl()+"/index.php?m=Admin&c=WechatEnt&a=getDeptById&token=ofanap1448334221&id=" + id,
        type: "GET",

        error: function () {
            alert('Error loading XML document');
        },
        success: function (data, status) { //如果调用php成功  
            // var data = JSON.parse(data);
            console.log(data);
            if (data.status == 0) {
                obj.attr('id','isvalue');
            } else {
                obj.next().remove();
                var str = "<select style='margin-top:10px' class='select_change form-control' id='parentid' name='parentid'><option value=''>请选择</option>";
                for (var i = 0; i < data.length; i++) {
                    str += '<option class="" value='+"'"+data[i].id+"'"+'>'+data[i].name+'</option>';
                }
                str += "</select>";
                $("#parent_dept").append(str);
            }
        }
    });
}

$(document).on("change",".select_change",function(){
        var id = $(this).val();
        $('select').removeClass('islast');
        $(this).addClass('islast');
    if(id==false){
        return false;
    }
     getSelect(id,$(this));
    // var islast = $('#golast').val();
    // alert(islast);
    // if(islast==1)
    //         $(this).attr('isLast',1);
});
function addSelect(value,obj){
       var id = value;
           $.ajax({
        url: $.getEnvUrl()+"/index.php?m=Admin&c=WechatEnt&a=getDeptById&token=ofanap1448334221&id=" + id,
        type: "GET",

        error: function () {
            alert('Error loading XML document');
        },
        success: function (data, status) { //如果调用php成功  
            // var data = JSON.parse(data);
            console.log(data);
            if (data.status == 0) {
                obj.attr('id','isvalue');
            } else {
                obj.next().remove();
                var str = "<select style='margin-top:10px' class='add_change form-control' id='parentid' name='parentid'><option value=''>请选择</option>";
                for (var i = 0; i < data.length; i++) {
                    str += '<option class="" value='+"'"+data[i].id+"'"+'>'+data[i].name+'</option>';
                }
                str += "</select>";
                $("#add_dept").append(str);
            }
        }
    });
}

$(document).on("change",".add_change",function(){
        var id = $(this).val();
        $('select').removeClass('isaddlast');
        $(this).addClass('isaddlast');
    if(id==false){
        return false;
    }
     addSelect(id,$(this));
    // var islast = $('#golast').val();
    // alert(islast);
    // if(islast==1)
    //         $(this).attr('isLast',1);
});